<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CompanyFile extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('company_file', ['comment' => '集团件表']);
        $table->addColumn('company_id', 'integer', ['comment' => '公司id', 'default' => 0])
              ->addColumn('company_user_id', 'integer', ['comment' => '上传者', 'default' => 0])
              ->addColumn('storage_type', 'string', ['comment' => '存储类型', 'default' => 'local'])
              ->addColumn('file_name', 'string', ['comment' => '文件名称', 'default' => ''])
              ->addColumn('file_path', 'string', ['comment' => '文件路径', 'default' => ''])
              ->addColumn('file_size', 'integer', ['comment' => '文件大小', 'default' => 0])
              ->addColumn('mime_type', 'string', ['comment' => '文件类型', 'default' => ''])
              ->addColumn('file_ext', 'string', ['comment' => '文件扩展名', 'default' => ''])
              ->addColumn('sort', 'integer', ['comment' => '排序', 'default' => 0])
              ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '状态 1正常 0禁用', 'default' => 1])
              ->addColumn('create_time', 'integer', ['comment' => '创建时间', 'default' => null])
              ->addColumn('update_time', 'integer', ['comment' => '更新时间', 'default' => null])
              ->addColumn('delete_time', 'integer', ['comment' => '删除时间', 'default' => null])
              ->addIndex(['company_id'], ['name' => 'idx_company_id'])
              ->addIndex(['company_user_id'], ['name' => 'idx_company_user_id'])
              ->create();
    }
}
